package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.SettingPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.SettingView
import com.weetop.cfw.bean.ErrorBean
import com.weetop.cfw.bean.SinglePageIntroduceBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.SettingActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class SettingPresenterImp(var settingView: SettingView? = null):SettingPresenter {

    /**
     * 获取关于我们的富文本数据
     */
    override fun getAboutUsData(settingActivity: SettingActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAppRelativeSinglePageIntroduce("appabout"),settingActivity,object:RxJavaCallBack<SinglePageIntroduceBean>(){

            override fun onSuccess(t: SinglePageIntroduceBean?) {
                settingView?.aboutUsDataDetSuccess(t)
            }

        })
    }

    /**
     * 退出登录
     */
    override fun logOut(settingActivity: SettingActivity) {
        settingActivity.showLoadingDialog(settingActivity,"正在退出...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().logOut(),settingActivity,object:RxJavaCallBack<ErrorBean>(){

            override fun onSuccess(t: ErrorBean?) {
                settingActivity.dismissLoadingDialog()
                settingView?.logOutSuccess(t)
            }

            override fun onRequestError(t: ErrorBean?) {
                super.onRequestError(t)
                settingActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                settingActivity.dismissLoadingDialog()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        settingView = baseView as? SettingView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       settingView = null
    }
}